<template>
  <div class="shop-item">

    <div class="item-selector">
      <!--向CheckButton子组件传递每个商品信息的选中状态-->
      <check-button
        :is-checked="product.checked"
        @click.native="checkClick(product.id)"><!-- 给子组件CheckButton绑定点击事件 -->
      </check-button>
    </div>

    <div class="item-img">
      <img :src="product.image">
    </div>

    <div class="item-info">
      <h3>{{ product.title }}</h3>
      <p>{{ product.desc }}</p>
      <div>
        <span class="info-price">￥{{ product.price }}</span>
        <span class="info-count">×{{ product.count }}</span>
      </div>
    </div>

  </div>
</template>

<script>
  import CheckButton from 'components/content/checkButton/CheckButton'

  export default {
    name: "",
    props: {
      product: {
        type: Object,
        default(){
          return {}
        }
      }
    },
    components: {
      CheckButton
    },
    methods: {
      checkClick(id){
        // this.product.checked = !this.product.checked
        this.$store.commit('updateCheckedById', id)
      }
    }
  }
</script>

<style lang="less" scoped>
  .shop-item{
    display: flex;
    padding: 10px 10px 10px 5px;
    height: 130px;
    /*justify-content: space-between;*/
    border-bottom: 1px solid #ccc;
  }
  .item-selector{
    padding-right: 5px;
    display: flex;
    flex-direction: column;
    justify-content: center;

  }
  .item-img{
    height: 100%;
  }
  .item-img img{
    display: block;
    height: 100%;
    width: 85px;
    border-radius: 10px;
  }
  .item-info{
    padding-left: 15px;
    overflow: hidden;
    /**/
  }
  .item-info h3,.item-info p{
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
  }
  .item-info h3{
    font-family: 华文仿宋;

  }
  .item-info p{
    margin: 20px 0 25px 0;
  }
  .info-price{
    color: coral;
    font-size: 20px;
  }
  .info-count{
    float: right;
    margin-right: 20px;
    font-size: 18px;
  }
</style>
